package com.xinwei.shard.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinwei.shard.entity.TUserInfo;
import com.xinwei.shard.service.UserInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 描述 用户信息控制类
 *
 * @author xinwei
 * @date 2024-04-26 17:16
 */
@RestController
@RequestMapping("/user")
public class UserInfoController {

    @Resource
    private UserInfoService userInfoService;
    @PostMapping("/insert")
    public void insert(@RequestBody TUserInfo userInfo) {
        List<TUserInfo> tUserInfos = new ArrayList<>();
        for (int i = 0; i < 60; i++) {
            TUserInfo tUserInfo = BeanUtil.copyProperties(userInfo, TUserInfo.class);
            tUserInfo.setAge(i);
            tUserInfo.setCreateTime(LocalDateTime.now());
            tUserInfos.add(tUserInfo);
        }
        userInfoService.saveBatch(tUserInfos);
    }

    @GetMapping("/list")
    public List<TUserInfo> query() {
        return userInfoService.queryUser();
    }

    @GetMapping("/list/page")
    public IPage<TUserInfo> queryPage() {
        IPage<TUserInfo> page = new Page<>();
        page.setSize(10);
        page.setCurrent(3);
        return userInfoService.selectPageVo(page);
    }
}
